/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objects;

import OBJ_Loader.AnimatedObject;
import OBJ_Loader.AnimatedObjectBase;
import org.lwjgl.util.vector.Vector3f;
import sun.applet.Main;

/**
 *
 * @author bwplo_000
 */
public class Base {
   public AnimatedObject b;
   private Vector3f pos = new Vector3f(0.0f,0.0f,0.0f);
   private Vector3f rot = new Vector3f(0.0f,0.0f,0.0f);
   public SRect rect = new SRect();
   private int ID;
   private float size = 1f;
   private Boolean opened = false;
   private Boolean opening = false;
   private Boolean closing = false;
       
    public void move(float x,float y, float z){
        pos.x = x;
        pos.y = y;
        pos.z = z;
       
    }
    public void setRot(float rot){
       this.rot.y = rot;
       
    }
    public Base(String type,float x,float y , float z, float scale){ 
        b = AnimatedObjectBase.o.get(type);
        ID = b.registerObject();
        pos.x = x;
        pos.y = y;
        pos.z = z;
        size*=scale;
        switch(type){
            case "base1": 
                this.rot.y = 270f;
                pos.x -= size;
                break;
        }
        
        rect.set(x-size, x+size, z-size, z+size);
       
        b.setAnimState(ID,AnimationState.STOP, 200);

    }
    public SRect getRect(){
        return rect;
    }
    public void draw(){
        if(this.opening){
            if(b.getI().get(ID).aframe == (b.getMax_aframes()-1)){
                this.opened = true;
                this.opening = false;
                 b.setAnimState(ID,AnimationState.PAUSE);
            }
        }else {
            if(this.closing){
                if(b.getI().get(ID).aframe == 0){
                    this.opened = false;
                    this.closing = false;
                     b.setAnimState(ID,AnimationState.PAUSE);
                }
            }
        }
        b.setRotateY(rot.y);
        b.move(pos.x, pos.y, pos.z);
        b.setScale(size);
        b.drawAnimated(ID);
    }
    public void openGate(){
        if(this.opened || this.opening || this.closing) return;
        b.setAnimState(ID,AnimationState.PLAY);
        this.opening = true;
    }
    public void closeGate(){
         if(!this.opened || this.opening || this.closing) return;
         b.setAnimState(ID,AnimationState.PLAY);
         this.closing = true;
    }
    public Boolean isOpened(){
        return this.opened;
    }
    
}
